const _ = require('lodash');
function calculateService($http) {





    function addCustomerAddr(addressInfo, callback) {
        var config = {

        };
        console.log(addressInfo);
        $http.post("/o2o/customer/updateInfo", addressInfo, config)
            .then(function (res) {
                console.log(res);
                callback(null, res.data);
            })
            .catch(function (err) {
                console.error(err);
                callback(err, null);
            });
    }

    function calTotalMoney(shoppingCart, callback){
        let totalMoney = 0;
        _.forEach(shoppingCart, (item) => {
            console.log("item.subTotalMoney___"+item.subTotalMoney);
            totalMoney += item.subTotalMoney;
        });
        callback(null, totalMoney);
    }

    function payFromOrderInfo(sendInfo, callback){
        var config = {};
        $http.post("/o2o/customer/addOrder", sendInfo, config).then((res) => {
            callback(null, res.data);
        }).catch((err) => {
            console.log("payFromOrderInfo..error");
            callback(err, null);
        })
    }
    return {
        addCustomerAddr: addCustomerAddr,
        calTotalMoney: calTotalMoney,
        payFromOrderInfo: payFromOrderInfo
    }

}

module.exports = calculateService;